#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
int BubbleSort(std::vector<int>&);

int main(int argc,char** argv)
{
    std::vector<int> ivec(10);
    srand(time(NULL));
    for(std::vector<int>::iterator i = ivec.begin(); i != ivec.end(); i++)
    {
        *i = rand()/1000;
    }

    std::cout << "排序前的元素:" << std::endl;

    for(std::vector<int>::iterator i = ivec.begin(); i != ivec.end(); i++)
    {
        std::cout << " " << *i;
    }
    std::cout << std::endl;
    
    BubbleSort(ivec);

    std::cout << "排序后的元素:" << std::endl;

    for(std::vector<int>::iterator i = ivec.begin(); i != ivec.end(); i++)
    {
        std::cout << " " << *i;
    }
    std::cout << std::endl;
    return 0;
}

int BubbleSort(std::vector<int> &ivec)
{
    for(std::vector<int>::size_type i = 0; i < ivec.size(); i++)
        for(std::vector<int>::size_type j = 0; j < (ivec.size() - i); j++)
        {
            if(ivec[j] > ivec[j+1])
            {
                int temp = ivec[j];
                ivec[j] = ivec[j+1];
                ivec[j+1] = temp;
            }
        }
    return 0;
}